/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simple.spc.tag;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
import simple.framework.util.cls;
import simple.framework.util.conf;

/**
 *
 * @author cxc
 */
public class ConfigTag extends TagSupport {

    Logger log = Logger.getLogger(ConfigTag.class.getName());
    private HttpServletRequest rq;
    private HttpServletResponse rp;
    private conf conf;
    private Iterator it = null;

    @Override
    public int doStartTag() {
        Collection tCollection = null;
        try {
            tCollection = getSysConfig();
        } catch (Exception ex) {
            log.info(ex.getMessage());
        }
        this.it = tCollection.iterator();
        if (this.it.hasNext()) {
            this.conf = ((conf) this.it.next());
            this.pageContext.setAttribute("spc_conf", this.conf);
            return 1;
        }
        return 0;
    }

    @Override
    public int doAfterBody() throws JspException {
        if (this.it.hasNext()) {
            this.conf = ((conf) this.it.next());
            this.pageContext.setAttribute("spc_conf", this.conf);
            return 2;
        }
        return 0;
    }

    public Collection getSysConfig() {
        Collection tCollection = null;
        try {
            tCollection = new ArrayList();
            conf cf = new conf();
            cf.Init(this.rq, this.rp);
            tCollection.add(cf);
        } catch (Exception e) {
            log.info(e.getMessage());
        }
        return tCollection;
    }

    public HttpServletResponse getRp() {
        return rp;
    }

    public void setRp(HttpServletResponse rp) {
        this.rp = rp;
    }

    public HttpServletRequest getRq() {
        return rq;
    }

    public void setRq(HttpServletRequest rq) {
        this.rq = rq;
    }
}
